package com.sky.controller.admin;

import com.sky.QueryByPage.DishQueryByPage;
import com.sky.dto.DishDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import com.sky.service.DishService;
import com.sky.vo.CategoryVO;
import com.sky.vo.DishVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/dish")
public class DishController {
    @Autowired
    private DishService dishService;
    @Autowired
    private CategoryService categoryService;
    @GetMapping("/page")
    public Result getByPage(DishQueryByPage dqbg){
        PageResult pageResult =  dishService.getByPage(dqbg);
        return Result.success(pageResult);
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        DishVO dishVO =  dishService.getById(id);
        return Result.success(dishVO);
    }

    @PutMapping
    public Result update(@RequestBody DishDTO dto){
        dishService.update(dto);
        return Result.success();
    }

    @DeleteMapping
    public Result delete(@RequestParam List<Integer> ids){
        dishService.delete(ids);
        return Result.success();
    }

    @PostMapping
    public Result add(@RequestBody DishDTO dto){
        dishService.add(dto);
        return Result.success();
    }

    @GetMapping("/list")
    public Result getlist(@RequestParam Integer categoryId){
        List<DishVO> dishVO = dishService.getList(categoryId);
        return Result.success(dishVO);

    }

    @PostMapping("/status/{status}")
    public Result enable(@PathVariable Integer status,@RequestParam Integer id){
        dishService.enable(status,id);
        return Result.success();
    }

}
